var id;
var groupid;
var iconid;
var subid;
var menuid;

$(function() {
  groupid = ly.getUrlParam("groupid");
  iconid = ly.getUrlParam("iconid");
  subid = ly.getUrlParam("subid");
  menuid = ly.getUrlParam("menuid");

  urlType = ly.getUrlParam("type");
  id = ly.getUrlParam("id");
  
  $('.whiteboard').remove();

  // 修改
  if (urlType == 2) {
    $(".title span").html("编辑");
    $(".form").getFormTwo({
      id: id,
      type: "post"
    }, function(data) {
    });
  // 新增
  } else {
  }

  //提交
  $("body").on("click", "#save-btn", function(event) {
    event.preventDefault();
    var success = $('.form').validate('submitValidate');
    if (success) {
      //验证通过提交表单
      submitFom();
    }
  })

});

/*
 * 提交表单
 */
function submitFom() {
  var webName = $("#webName").val();
  var webAddress = $("#webAddress").val();

  var url = site.apiUrl + "/webInfo/addAddressSetting";
  var obj = {
    'webName': webName,
    'webAddress': webAddress
  };
  if (urlType == 1) {
    //新增
  } else {
    //修改
    var thisId = $("#currentId").val();
    obj.id = thisId;
  }
  request({
    url: url,
    data: obj,
    type: "post",
    ajaxform: "true",
    callback: function(f) {
      if (f.code == 200) {
        if (urlType == 1) {
          ly.alert('保存成功', function() {
            ly.goto("list.html");
          });
        } else {
          ly.alert('修改成功', function() {
            ly.goto("list.html");
          });
        }
      } else {
        ly.toast(f.msg);
      }
    }
  });
}
